<?php

/**
 * Users
 * 
 * @author NguyenVanTien
 * @version 
 */
class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract {

    /**
     * The default table name 
     */
    protected $_name = 'users';
    protected $_primary = 'user_id';
    
    /**
     * return 
     * @param type $username
     * @return Zend_Db_Row_Abstract 
     */
    public function getByUsername($username){
        $row = $this->fetchRow('username = '. $this->getAdapter()->quote($username));
        return $row;
    }
    
    /**
     * Edit save data
     * @author Tien Nguyen
     * @param array $data
     * @return boolean 
     */
    public function edit($data){
        $row = $this->find($data['user_id'])->current();
        if($row){
            $row->setFromArray($data);
            return $row->save();
        }
        return false;
    }
    
    /**
     * add User 
     * @param type $data
     * @return int 
     */
    public function addUser($data){
        //Zend_Debug::dump($data); die;
        unset ($data['user_id']);
        return $this->createRow($data)->save();
    }
}

